import 'package:flutter/material.dart';
import 'package:flutter_fun_app/model/videoListModel.dart';
import 'package:chewie/chewie.dart';
import 'package:video_player/video_player.dart';

class VideoDetailPage extends StatefulWidget {
  VideoResult result;

  VideoDetailPage(this.result);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return VideoDetailState(result);
  }
}

class VideoDetailState extends State<VideoDetailPage> {
  VideoResult result;

  VideoDetailState(this.result);

  VideoPlayerController _videoPlayerController1;
  ChewieController _chewieController;

  @override
  void initState() {
    super.initState();
    _videoPlayerController1 = VideoPlayerController.network(
        result.data.content.data.playUrl);
    _chewieController = ChewieController(
      videoPlayerController: _videoPlayerController1,
      aspectRatio: 4 / 2,
      autoPlay: true,
      looping: true,
      // Try playing around with some of these other options:

      // showControls: false,
      // materialProgressColors: ChewieProgressColors(
      //   playedColor: Colors.red,
      //   handleColor: Colors.blue,
      //   backgroundColor: Colors.grey,
      //   bufferedColor: Colors.lightGreen,
      // ),
      // placeholder: Container(
      //   color: Colors.grey,
      // ),
      // autoInitialize: true,
    );
  }

  @override
  void dispose() {
    _videoPlayerController1.dispose();
    _chewieController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(result.data.content.data.title),
      ),
      body: Container(
        height: 207,
        alignment: Alignment.topCenter,
        child: Chewie(
          controller: _chewieController,
        ),
      ),
    );
  }
}
